package com.itheima.service.imp;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.OrderSettingDao;
import com.itheima.pojo.OrderSetting;
import com.itheima.service.OrderSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(interfaceClass = OrderSettingService.class)
@Transactional
public class OrderSettingServiceImpl implements OrderSettingService {

    @Autowired
    private OrderSettingDao orderSettingDao;

    @Override
    public void add(List<OrderSetting> orderSettingList) {
        if(orderSettingList!=null && orderSettingList.size()>0){
            /*判断数据库中是否有日期数据
            有就更新数据
            没有就新增数据
              */
            for (OrderSetting orderSetting : orderSettingList) {
               long ifExist = orderSettingDao.findCountByDate(orderSetting.getOrderDate());

               if(ifExist>0){
//                   有数据修改数据
                   orderSettingDao.update(orderSetting);

               }else{
//                   没有数据新增
                   orderSettingDao.add(orderSetting);
               }

            }
        }
    }

    @Override
    public List<Map> getOrdersettingByMonth(String date) {

        List<Map> list = orderSettingDao.getOrdersettingByMonth(date);

        return list;
    }

    @Override
    public void setdateNumber(OrderSetting orderSetting) {
        orderSettingDao.update(orderSetting);
    }
}
